<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="robots" content="noindex,nofollow" /> 
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
  <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
  <link rel="stylesheet" href="__CSS__/common.css"  media="all">
  <style type="text/css">

    /* tooltip */
    #tooltip{
      position:absolute;
      border:1px solid #ccc;
      background:#333;
      padding:2px;
      display:none;
      color:#fff;
    }
    tr{
      height: 40px;
      line-height: 40px;
      color:#5F6E82;
    }
    td>input{
      text-align: center;
      border:1px solid #E2E9F1;
      outline: none;
      padding:3px 5px;
    }
    .layui-btn-group a:nth-child(2){
      margin:0 15px !important;
    }
    button.new-btn-style{
      height:38px;
      line-height: 38px;
    }
  </style>
</head>
<body class="page-body">
<h2 class="comm-title">菜单管理</h2>
<div class="layui-tab">
  <ul class="layui-tab-title page-tab-title">
    <li class="layui-this">系统菜单管理</li>
    <li class="add_menu">添加新菜单</li>
    <!-- <li><a href="{:url('admin/menu/publish')}">添加新菜单</a></li> -->
  </ul>
</div>
<div class="tpcms-body-div page-main">
  <table class="layui-table page-table" lay-size="sm">
    <colgroup>
      <col width="50">
      <col width="70">
      <col width="250">
      <col width="100">
      <col width="100">
      <col width="100">
      <col width="200">
      <col width="100">
      <col width="130">
      <col width="150">
      <col width="200">
    </colgroup>
    <thead>
    <tr>
      <th>排序</th>
      <th>编号</th>
      <th>名称</th>
      <th>模块</th>
      <th>控制器</th>
      <th>方法</th>
      <th>备注</th>
      <th>类型</th>
      <th>状态</th>
      <th>创建时间</th>
      <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <form class="layui-form" id="admin">
      {volist name="menus" id="vo"}
      <tr>
        <td><input type="text" name="orders[]" value="{$vo.orders}" style="width: 20px;" class="orders"><input type="hidden" name="id[]" value="{$vo.id}"></td>
        <td>{$vo.id}</td>
        <td><span style="font-weight:500;">{$vo.str|raw}</span>{$vo.name}</td>
        <td>{$vo.module}</td>
        <td>{$vo.controller}</td>
        <td>{$vo.function}</td>
        <td>{$vo.description}</td>
        <td>{eq name="$vo.type" value="1"}权限节点{else /}普通节点{/eq}</td>
        <td>{eq name="$vo.is_display" value="1"}显示在左侧菜单{else /}只做为操作节点{/eq}</td>
        <td>{$vo.create_time}</td>
        <td class="operation-menu">
          <div class="layui-btn-group">
            <a href="javascript:;" class="layui-btn layui-btn-xs a_menu layui-btn-primary btn-edit add_menu" data-pid="{$vo.id}">添加</a>
            <a href="javascript:;" class="layui-btn layui-btn-xs a_menu layui-btn-primary btn-edit edit_menu" data-ids="{$vo.id}">编辑</a>
            <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-primary delete btn-edit" id="{$vo.id}">删除</a>
          </div>
        </td>
      </tr>
      {/volist}
    </tbody>
  </table>
  <button class="layui-btn layui-btn-sm new-btn-style" lay-submit lay-filter="admin">更新排序</button>
  </form>
  <script src="__PUBLIC__/jquery/jquery.min.js"></script>
  <script src="__PUBLIC__/layui/layui.js"></script>
  <script type="text/javascript">
    
    $('.add_menu').click(function(){
      var pid = $(this).data('pid');
      var url = "{:url('admin/menu/publish')}";
      if(pid > 0){
          url = "{:url('admin/menu/publish')}?pid="+pid;
      }
      layer.open({
        title: false,
        shadeClose: true,
        shade: 0.6,
        skin: "edit_layer",
        title: false,
        type: 2,
        area: ['80%', '98%'],
        content: url
      });
    })
    $('.edit_menu').click(function(){
      var ids = $(this).data('ids');
      layer.open({
        title: false,
        shadeClose: true,
        shade: 0.6,
        skin: "edit_layer",
        title: false,
        type: 2,
        area: ['80%', '98%'],
        content: "{:url('admin/menu/publish')}?id="+ids+"&types=1"
      });
    })

    $('.delete').click(function(){
      var id = $(this).attr('id');
      layer.confirm('确定要删除?', function(index) {
        $.ajax({
          url:"{:url('admin/menu/delete')}",
          data:{id:id},
          success:function(res) {
            layer.msg(res.msg);
            if(res.code == 1) {
              setTimeout(function(){
                location.href = res.url;
              },1500)
            }
          }
        })
      })
    })
  </script>

  <script>
    layui.use(['layer', 'form'], function() {
      var layer = layui.layer,
              $ = layui.jquery,
              form = layui.form;
      $(window).on('load', function() {
        form.on('submit(admin)', function(data) {
          $.ajax({
            url:"{:url('admin/menu/orders')}",
            data:$('#admin').serialize(),
            type:'post',
            async: false,
            success:function(res) {
              if(res.code == 1) {
                layer.alert(res.msg, function(index){
                  location.href = res.url;
                })
              } else {
                layer.msg(res.msg);
              }
            }
          })
          return false;
        });
      });
    });
  </script>
</div>
</body>
</html>
